class userListManager {
    static sp_name = "sp_userList";
    static saveUser(username, password){
        let userList = userListManager.getUserList();
        if(userList == null) {
            userList = {};
        }
        userList[username] = password;
        // 最多存入五个用户
        if(Object.keys(userList).length > 5) {
            let keys = Object.keys(userList);
            // 将多余的都删除
            for(let i = 0; i < keys.length - 5; i++) {
                delete userList[keys[i]];
            }
            JSBridge.showToast("最多存储5个账号密码到本地");
        }
        window.JSBridge.saveSharedPreferencesByName(userListManager.sp_name, JSON.stringify(userList));
    }

    static getUserList() {
        let userList = window.JSBridge.getSharedPreferencesByName(userListManager.sp_name);
        return userList ? JSON.parse(userList): null;
    }
}
